using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DAL;
using BLL;
using DTO;

namespace WellmeadowsHospital
{
    public partial class frmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public static string bsiwardid="";
        UserBLL userBLL = new UserBLL();
        StaffOfWardBLL sowBLL = new StaffOfWardBLL();
        public frmMain()
        {
            InitializeComponent();
            bsiwardid = bsiWardID.Caption;
        }

        private void bbtnAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAddStaff.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabAddStaff);
            }
            if (xtcHome.SelectedTabPage != xtraTabAddStaff)
            {
                xtcHome.SelectedTabPage = xtraTabAddStaff;
            }
            //xtcHome.TabPages.Add(xtraTabAddStaff);
            xtraTabAddStaff.Controls.Clear();
            frmAddStaff frm = new frmAddStaff();
            xtraTabAddStaff.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
            
        }

        private void bbtnSearch_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabSearchStaff.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabSearchStaff);
            }
            if (xtcHome.SelectedTabPage != xtraTabSearchStaff)
            {
                xtcHome.SelectedTabPage = xtraTabSearchStaff;
            }
            //xtcHome.TabPages.Add(xtraTabSearchStaff);
            xtraTabSearchStaff.Controls.Clear();
            frmSearchStaff frm = new frmSearchStaff();
            xtraTabSearchStaff.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void bbtnAllocated_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAllocated.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabAllocated);
            }
            if (xtcHome.SelectedTabPage != xtraTabAllocated)
            {
                xtcHome.SelectedTabPage = xtraTabAllocated;
            }
           // xtcHome.TabPages.Add(xtraTabAllocated);
            xtraTabAllocated.Controls.Clear();
            frmAllocated frm = new frmAllocated();
            xtraTabAllocated.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (userBLL.CheckLogin(txtUserName.Text, txtPassword.Text))
            {
                bsiStaffID.Visibility = BarItemVisibility.Always;
                bbtnLogout.Visibility = BarItemVisibility.Always;
                xtcHome.TabPages.Add(xtraTabAddStaff);
                xtraTabAddStaff.Controls.Add(new frmAddStaff());
                xtcHome.TabPages.Remove(xtraTabLogin);
                bsiStaffID.Caption = txtUserName.Text;
                rpHome.Visible = true;

                if (userBLL.getRole(txtUserName.Text).Equals("Medical Director"))
                {
                    rpPatient.Visible = true;
                    rpStaff.Visible = true;
                    rpSupplier.Visible = true;
                }
                if (userBLL.getRole(txtUserName.Text).Equals("Charge Nurse"))
                {
                    rpStaff.Visible = true;
                    bsiWardID.Visibility = BarItemVisibility.Always;
                    bsiWardID.Caption = userBLL.getWardID(txtUserName.Text);
                    bsiwardid = bsiWardID.Caption;

                }
                if (userBLL.getRole(txtUserName.Text).Equals("Personnel Officer"))
                {
                    rpPatient.Visible = true;
                    rpStaff.Visible = true;
                }
            }
            else
            {
                MessageBox.Show("Login fail");
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            //an tat ca cac thanh manager
            rpHome.Visible = false;
            rpStaff.Visible = false;
            rpPatient.Visible = false;
            rpSupplier.Visible = false;
            //bsiStaffID.Visibility = BarItemVisibility.OnlyInRuntime;
            //bbtnLogout.Visibility = BarItemVisibility.OnlyInRuntime;
            bsiStaffID.Visibility = BarItemVisibility.Never;
            bbtnLogout.Visibility = BarItemVisibility.Never;
            bsiWardID.Visibility = BarItemVisibility.Never;
            //tat bo tat ca  cac tab
            while (xtcHome.TabPages.Count != 0)
            {
                for (int i = 0; i < xtcHome.TabPages.Count; i++)
                {
                    xtcHome.TabPages.RemoveAt(i);
                }
            }
            //mac dinh la tab Home
            xtcHome.TabPages.Add(xtraTabLogin);
            txtPassword.Focus();
            //xtcHome.TabPages.Add(xtraTabListStaffReport);
            //GridBandCollection gr1 = new GridBandCollection();
            //GridBand gr2 = new GridBand { Name = "Ho" };
            //GridBand gr3 = new GridBand { Name = "Ten" };
            //gr1. = gr2;
            //gr1.Children = gr3;
            //bandedGridView1.Bands.Add(gr1);

            //gridControl1.DataSource = staffBLL.SelectAll2();
            //gridControl1.UseEmbeddedNavigator = true;

            //controlNavigator1.NavigatableControl = gridControl1;
            //controlNavigator1.
            //controlNavigator1.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(Grid_EmbeddedNavigator_ButtonClick);
            //gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(Grid_EmbeddedNavigator_ButtonClick);

        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAllocated.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabListStaffReport);
            }
            if (xtcHome.SelectedTabPage != xtraTabListStaffReport)
            {
                xtcHome.SelectedTabPage = xtraTabListStaffReport;
            }
            xtraTabListStaffReport.Controls.Clear();
            frmListStaffReport frm = new frmListStaffReport();
            xtraTabListStaffReport.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnLogin.PerformClick();
        }

        private void bbtnAddUsers_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabUserManagerment.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabUserManagerment);
            }
            if (xtcHome.SelectedTabPage != xtraTabUserManagerment)
            {
                xtcHome.SelectedTabPage = xtraTabUserManagerment;
            }
            xtraTabUserManagerment.Controls.Clear();
            frmUserManagement frm = new frmUserManagement();
            xtraTabUserManagerment.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAddPatients.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabAddPatients);
            }
            if (xtcHome.SelectedTabPage != xtraTabAddPatients)
            {
                xtcHome.SelectedTabPage = xtraTabAddPatients;
            }
            xtraTabAddPatients.Controls.Clear();
            frmAddPatients frm = new frmAddPatients();
            xtraTabAddPatients.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabSearchPatients.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabSearchPatients);
            }
            if (xtcHome.SelectedTabPage != xtraTabSearchPatients)
            {
                xtcHome.SelectedTabPage = xtraTabSearchPatients;
            }
            xtraTabSearchPatients.Controls.Clear();
            frmSearchPatients frm = new frmSearchPatients();
            xtraTabSearchPatients.Controls.Add(frm);
        }

        private void barButtonItem5_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAddAppointment.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabAddAppointment);
            }
            if (xtcHome.SelectedTabPage != xtraTabAddAppointment)
            {
                xtcHome.SelectedTabPage = xtraTabAddAppointment;
            }
            xtraTabAddAppointment.Controls.Clear();
            frmAddAppointment frm = new frmAddAppointment();
            xtraTabAddAppointment.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem6_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabSearchAppointment.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabSearchAppointment);
            }
            if (xtcHome.SelectedTabPage != xtraTabSearchAppointment)
            {
                xtcHome.SelectedTabPage = xtraTabSearchAppointment;
            }
            xtraTabSearchAppointment.Controls.Clear();
            frmSearchAppointment frm = new frmSearchAppointment();
            xtraTabSearchAppointment.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem7_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAddWaitList.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabAddWaitList);
            }
            if (xtcHome.SelectedTabPage != xtraTabAddWaitList)
            {
                xtcHome.SelectedTabPage = xtraTabAddWaitList;
            }
            xtraTabAddWaitList.Controls.Clear();
            frmAddWaitList frm = new frmAddWaitList();
            xtraTabAddWaitList.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem8_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabSearchWaitList.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabSearchWaitList);
            }
            if (xtcHome.SelectedTabPage != xtraTabSearchWaitList)
            {
                xtcHome.SelectedTabPage = xtraTabSearchWaitList;
            }
            xtraTabSearchWaitList.Controls.Clear();
            frmSearchListWait frm = new frmSearchListWait();
            xtraTabSearchWaitList.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem9_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabAppointmentClinic.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabAppointmentClinic);
            }
            if (xtcHome.SelectedTabPage != xtraTabAppointmentClinic)
            {
                xtcHome.SelectedTabPage = xtraTabAppointmentClinic;
            }
            xtraTabAppointmentClinic.Controls.Clear();
            frmAddOutPatients frm = new frmAddOutPatients();
            xtraTabAppointmentClinic.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
        }

        private void barButtonItem10_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabSearchAppointmentClinic.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabSearchAppointmentClinic);
            }
            if (xtcHome.SelectedTabPage != xtraTabSearchAppointmentClinic)
            {
                xtcHome.SelectedTabPage = xtraTabSearchAppointmentClinic;
            }
            xtraTabSearchAppointmentClinic.Controls.Clear();
            frmSearchOutPatients frm = new frmSearchOutPatients();
            frm.Dock = DockStyle.Fill;
            xtraTabSearchAppointmentClinic.Controls.Add(frm);
        }

        private void barButtonItem13_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabPlaceInPatients.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabPlaceInPatients);
            }
            if (xtcHome.SelectedTabPage != xtraTabPlaceInPatients)
            {
                xtcHome.SelectedTabPage = xtraTabPlaceInPatients;
            }
            xtraTabPlaceInPatients.Controls.Clear();
            frmPlaceInPatients frm = new frmPlaceInPatients();
            xtraTabPlaceInPatients.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
       
        }

        private void barButtonItem11_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabSearchInpatients.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabSearchInpatients);
            }
            if (xtcHome.SelectedTabPage != xtraTabSearchInpatients)
            {
                xtcHome.SelectedTabPage = xtraTabSearchInpatients;
            }
            xtraTabSearchInpatients.Controls.Clear();
            frmSearchInPatients frm = new frmSearchInPatients();
            xtraTabSearchInpatients.Controls.Add(new frmSearchInPatients());
            frm.Dock = DockStyle.Fill;
        }

        private void bbtnLogout_ItemClick(object sender, ItemClickEventArgs e)
        {
            DialogResult result2 = MessageBox.Show("Are you sure logout?",
        "Logout",
        MessageBoxButtons.YesNoCancel,
        MessageBoxIcon.Question);
            if (result2 == DialogResult.Yes)
            {
                //an tat ca cac thanh manager
                rpHome.Visible = false;
                rpStaff.Visible = false;
                rpPatient.Visible = false;
                rpSupplier.Visible = false;
                //tat bo tat ca  cac tab
                while (xtcHome.TabPages.Count != 0)
                {
                    for (int i = 0; i < xtcHome.TabPages.Count; i++)
                    {
                        xtcHome.TabPages.RemoveAt(i);
                    }
                }
                //mac dinh la tab Home
                xtcHome.TabPages.Add(xtraTabLogin);
                bsiStaffID.Visibility = BarItemVisibility.Never;
                bbtnLogout.Visibility = BarItemVisibility.Never;
            }
        }

        private void barButtonItem12_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabReportPatientCrrent.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabReportPatientCrrent);
            }
            if (xtcHome.SelectedTabPage != xtraTabReportPatientCrrent)
            {
                xtcHome.SelectedTabPage = xtraTabReportPatientCrrent;
            }
            xtraTabReportPatientCrrent.Controls.Clear();
            xtraTabReportPatientCrrent.Controls.Add(new frmRePortPatientCurrent());
        }

        private void barButtonItem14_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (xtraTabReportPatientOnListwait.IsAccessible == false)
            {
                xtcHome.TabPages.Add(xtraTabReportPatientOnListwait);
            }
            if (xtcHome.SelectedTabPage != xtraTabReportPatientOnListwait)
            {
                xtcHome.SelectedTabPage = xtraTabReportPatientOnListwait;
            }
            xtraTabReportPatientOnListwait.Controls.Clear();
            xtraTabReportPatientOnListwait.Controls.Add(new frmReportPatientONLIstWait());
        }

        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void ribbon_Click(object sender, EventArgs e)
        {

        }
    }
}